package main

import (
	"context"
	"log"
	"fmt"
	
	"github.com/tmc/langchaingo/agents"
	"github.com/tmc/langchaingo/chains"
	"github.com/tmc/langchaingo/llms/openai"
	"github.com/tmc/langchaingo/tools"
	"mcpGoSource/common/consts"
	"mcpGoSource/llmtools"
)

func main() {
	// 启动 openai 兼容的大模型
	llm, err := openai.New(
		openai.WithBaseURL(consts.AliYunOpenAi),
		openai.WithToken(consts.AliYunOpenAiToken),
		openai.WithModel(consts.AliYunOpenAiModel),
	)
	if err != nil {
		log.Fatalf("openai.New failed: %v", err)
		return
	}

	// 初始化并注册工具
	weatherTool, err := llmtools.NewWeatherTool()
	if err != nil {
		log.Fatalf("llmtools.NewWeatherTool failed: %v", err)
		return
	}
	agentTools := []tools.Tool{
		weatherTool,
	}
	agent := agents.NewOneShotAgent(llm, agentTools, agents.WithMaxIterations(3))
	executor := agents.NewExecutor(agent)

	// 提问
	question := "查询深圳未来3天的天气,并给出出行建议."

	// 调用大模型,得到回答
	answer, err := chains.Run(context.Background(), executor, question)
	if err != nil {
		log.Fatalf("chains.Run failed: %v", err)
		return
	}
	fmt.Println(answer)
}
